Skip to content

fix(astro): Do not inject withSentry into Cloudflare Pages#19558

Open
JPeer264 wants to merge 2 commits intodevelopfrom
jp/cloudflare-pages
Open

fix(astro): Do not inject withSentry into Cloudflare Pages#19558
JPeer264 wants to merge 2 commits intodevelopfrom
jp/cloudflare-pages

Conversation

@JPeer264
Copy link
Member

@JPeer264 JPeer264 commented Feb 27, 2026

When running on Cloudflare Pages the withSentry function got bundled and wrapped into the index.js. This actually didn't cause any problems during the runtime, but it just added unnecessary code into the bundle. This removes now the automatic wrapping, which is required for Cloudflare Workers only.

By adding the plugin sentryCloudflareNodeWarningPlugin we also remove tons of warnings like following when building for Cloudflare Pages:

11:20:40 [WARN] [vite] [plugin vite:resolve] Automatically externalized node built-in module "node:diagnostics_channel" imported from "node_modules/.pnpm/@sentry+node@10.40.0/node_modules/@sentry/node/build/esm/integrations/tracing/fastify/index.js". Consider adding it to environments.ssr.external if it is intended.
11:20:40 [WARN] [vite] [plugin vite:resolve] Automatically externalized node built-in module "node:diagnostics_channel" imported from "node_modules/.pnpm/@sentry+node-core@10.40.0_@opentelemetry+api@1.9.0_@opentelemetry+context-async-hooks@2_feb79575758996d9eeb93d3eb9a5534b/node_modules/@sentry/node-core/build/esm/integrations/http/httpServerIntegration.js". Consider adding it to environments.ssr.external if it is intended.

Closes #19559 (added automatically)

@github-actions
Copy link
Contributor

github-actions bot commented Feb 27, 2026

size-limit report 📦

Path Size % Change Change
@sentry/browser 25.63 kB added added
@sentry/browser - with treeshaking flags 24.13 kB added added
@sentry/browser (incl. Tracing) 42.43 kB added added
@sentry/browser (incl. Tracing, Profiling) 47.09 kB added added
@sentry/browser (incl. Tracing, Replay) 81.25 kB added added
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 70.87 kB added added
@sentry/browser (incl. Tracing, Replay with Canvas) 85.95 kB added added
@sentry/browser (incl. Tracing, Replay, Feedback) 98.21 kB added added
@sentry/browser (incl. Feedback) 42.44 kB added added
@sentry/browser (incl. sendFeedback) 30.29 kB added added
@sentry/browser (incl. FeedbackAsync) 35.35 kB added added
@sentry/browser (incl. Metrics) 26.8 kB added added
@sentry/browser (incl. Logs) 26.94 kB added added
@sentry/browser (incl. Metrics & Logs) 27.61 kB added added
@sentry/react 27.38 kB added added
@sentry/react (incl. Tracing) 44.77 kB added added
@sentry/vue 30.08 kB added added
@sentry/vue (incl. Tracing) 44.3 kB added added
@sentry/svelte 25.66 kB added added
CDN Bundle 28.17 kB added added
CDN Bundle (incl. Tracing) 43.26 kB added added
CDN Bundle (incl. Logs, Metrics) 29.01 kB added added
CDN Bundle (incl. Tracing, Logs, Metrics) 44.1 kB added added
CDN Bundle (incl. Replay, Logs, Metrics) 68.09 kB added added
CDN Bundle (incl. Tracing, Replay) 80.14 kB added added
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 81 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) 85.65 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 86.53 kB added added
CDN Bundle - uncompressed 82.35 kB added added
CDN Bundle (incl. Tracing) - uncompressed 128.07 kB added added
CDN Bundle (incl. Logs, Metrics) - uncompressed 85.19 kB added added
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 130.9 kB added added
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 208.85 kB added added
CDN Bundle (incl. Tracing, Replay) - uncompressed 244.95 kB added added
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 247.77 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 257.86 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 260.67 kB added added
@sentry/nextjs (client) 47.18 kB added added
@sentry/sveltekit (client) 42.89 kB added added
@sentry/node-core 52.24 kB added added
@sentry/node 174.69 kB added added
@sentry/node - without tracing 97.39 kB added added
@sentry/aws-serverless 113.19 kB added added

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: JSONC regex matches pages_build_output_dir inside comments
    • Added line-start anchoring (^\s*) with multiline flag to the JSON/JSONC regex to match the TOML behavior and prevent false positives from commented-out keys in JSONC files.

Create PR

Or push these changes by commenting:

@cursor push 232e46c4ee
Preview (232e46c4ee)
diff --git a/packages/astro/src/integration/index.ts b/packages/astro/src/integration/index.ts
--- a/packages/astro/src/integration/index.ts
+++ b/packages/astro/src/integration/index.ts
@@ -284,9 +284,9 @@
       return /^\s*pages_build_output_dir\s*=/m.test(content);
     }
 
-    // Match "pages_build_output_dir" as a JSON key (followed by :)
-    // This works for both .json and .jsonc without needing to strip comments
-    return /"pages_build_output_dir"\s*:/.test(content);
+    // Match "pages_build_output_dir" as a JSON key (at start of line, ignoring whitespace)
+    // This avoids false positives from comments in .jsonc files (lines starting with //)
+    return /^\s*"pages_build_output_dir"\s*:/m.test(content);
   }
 
   return false;

diff --git a/packages/astro/test/integration/cloudflare.test.ts b/packages/astro/test/integration/cloudflare.test.ts
--- a/packages/astro/test/integration/cloudflare.test.ts
+++ b/packages/astro/test/integration/cloudflare.test.ts
@@ -174,9 +174,9 @@
         command: 'build',
       });
 
-      expect(baseConfigHookObject.updateConfig).toHaveBeenCalledWith(
-        { vite: expect.objectContaining({ plugins: ['sentryCloudflareNodeWarningPlugin'] }) },
-      );
+      expect(baseConfigHookObject.updateConfig).toHaveBeenCalledWith({
+        vite: expect.objectContaining({ plugins: ['sentryCloudflareNodeWarningPlugin'] }),
+      });
     });
 
     it('correctly parses wrangler.jsonc with URLs and comments', async () => {
@@ -206,9 +206,9 @@
         command: 'build',
       });
 
-      expect(baseConfigHookObject.updateConfig).toHaveBeenCalledWith(
-        { vite: expect.objectContaining({ plugins: ['sentryCloudflareNodeWarningPlugin'] }) },
-      );
+      expect(baseConfigHookObject.updateConfig).toHaveBeenCalledWith({
+        vite: expect.objectContaining({ plugins: ['sentryCloudflareNodeWarningPlugin'] }),
+      });
     });
 
     it('does not show warning for Pages project with wrangler.toml', async () => {
@@ -290,9 +290,9 @@
       });
 
       // Check that sentryCloudflareVitePlugin is NOT in any of the calls
-      expect(baseConfigHookObject.updateConfig).toHaveBeenCalledWith(
-        { vite: expect.objectContaining({ plugins: ['sentryCloudflareNodeWarningPlugin'] }) },
-      );
+      expect(baseConfigHookObject.updateConfig).toHaveBeenCalledWith({
+        vite: expect.objectContaining({ plugins: ['sentryCloudflareNodeWarningPlugin'] }),
+      });
     });
 
     it('still adds SSR noExternal config for Pages in dev mode', async () => {
This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.


// Match "pages_build_output_dir" as a JSON key (followed by :)
// This works for both .json and .jsonc without needing to strip comments
return /"pages_build_output_dir"\s*:/.test(content);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSONC regex matches pages_build_output_dir inside comments

Low Severity

The TOML regex uses ^\s* anchoring with the m flag to avoid matching pages_build_output_dir inside # comments, but the JSON/JSONC regex /"pages_build_output_dir"\s*:/ has no such protection. In a .jsonc file, a commented-out key like // "pages_build_output_dir": "./dist" would still match, causing a Workers project to be misidentified as Pages. This would skip the withSentry wrapper, losing async context propagation and per-request isolation. Anchoring the JSON regex to start-of-line (/^\s*"pages_build_output_dir"\s*:/m) would provide equivalent comment safety as the TOML path.

Additional Locations (1)

Fix in Cursor Fix in Web

@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

node-overhead report 🧳

Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 8,735 - 9,128 -4%
GET With Sentry 1,672 19% 1,713 -2%
GET With Sentry (error only) 6,116 70% 6,167 -1%
POST Baseline 1,195 - 1,183 +1%
POST With Sentry 589 49% 593 -1%
POST With Sentry (error only) 1,063 89% 1,028 +3%
MYSQL Baseline 3,267 - 3,235 +1%
MYSQL With Sentry 363 11% 490 -26%
MYSQL With Sentry (error only) 2,597 79% 2,623 -1%

View base workflow run

@JPeer264 JPeer264 force-pushed the jp/cloudflare-pages branch from 8c5293f to c707de2 Compare March 3, 2026 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(astro): Do not inject withSentry into Cloudflare Pages

2 participants